<?php

/**
 * @desc Position utility. 
 *
 */
class Kernel_Form_Value_Position implements Kernel_Form_Value_Interface 
{
    
    /**
    * @desc Table name.
    * 
    * @param string
    */
    private $_table; 
    
    /**
    * @desc Whether form is new.
    * 
    * @param boolean
    */
    private $_is_new; 
    
    
    
    public function __construct($table, $is_new) 
    {
        $this->_table = $table;
        $this->_is_new = (bool)$is_new;
    }
    
    public function values() 
    {
        static $_cach = array();
        
        if (empty($_cach)) {
            $query = '
                SELECT 
                       COUNT(*) 
                  FROM 
                       ' . $this->_table;
            
            if (0 == database::fetchOne($query)) {
                $elements = range(1, 1);
            } else {
                $elements = range(1, $this->_is_new 
                    ? database::fetchOne($query) + 1 
                    : database::fetchOne($query));
            }
            $_cach = array_combine($elements, $elements);
        }
        
        return $_cach;
    }
    
    public function isBlank() {}
    
}